package org.balthie.demo.jvm.classloader.lifecircle;

//class半初始化： jvm对class延迟加载，未被调用过的class处于半初始化状态（成员变量都是初始值）
public class HalfInitializeTest {
	
	public static void main(String[] args) {
//		ClassLayoutUtil.printClass(SomeClass.class);
		System.out.println();
//		第一次使用类时，类的static 成员都是半初始化状态，jvm给其赋类型默认值（0），并按顺序执行  = 号右边的复制语句
		System.out.println("SomeClass have money "+SomeClass.money+" have apple " + SomeClass.inst.appleCount );
		System.out.println();
//		ClassLayoutUtil.printObject(SomeClass.inst);
		
//		第二次使用类时，类的static 成员不再是半初始化状态，打印信息正常
		System.out.println(new SomeClass(10) +"SomeClass have money "+SomeClass.money+" have apple " + SomeClass.inst.appleCount );
		 
//		第三次使用类时，类的static 成员不再是半初始化状态，打印信息正常
		System.out.println(new SomeClass(10) +"SomeClass have money "+SomeClass.money+" have apple " + SomeClass.inst.appleCount );
	}
}
//java.lang.Class object internals:  //SomeClass.class
//	 OFFSET  SIZE                                              TYPE DESCRIPTION                               VALUE
//	      0     4                                                   (object header)                           01 00 00 00 (00000001 00000000 00000000 00000000) (1)
//	      4     4                                                   (object header)                           00 00 00 00 (00000000 00000000 00000000 00000000) (0)
//	      8     4                                                   (object header)                           f9 84 00 20 (11111001 10000100 00000000 00100000) (536904953)   java.lang.Class对象 
//	     12     4                                               int Class.classRedefinedCount                 0
//	     16    24                                                   (alignment/padding gap)                  
//	     40     4                     java.lang.reflect.Constructor Class.cachedConstructor                   null
//	     44     4                                  java.lang.String Class.name                                (object)
//	     48     4                                  java.lang.Module Class.module                              (object)
//	     52     8                                                   (alignment/padding gap)                  
//	     60     4                                  java.lang.String Class.packageName                         (object)
//	     64     4                                   java.lang.Class Class.componentType                       []
//	     68     4                       java.lang.ref.SoftReference Class.reflectionData                      null
//	     72     4   sun.reflect.generics.repository.ClassRepository Class.genericInfo                         null
//	     76     4                                java.lang.Object[] Class.enumConstants                       null
//	     80     4                                     java.util.Map Class.enumConstantDirectory               null
//	     84     4                    java.lang.Class.AnnotationData Class.annotationData                      null
//	     88     4             sun.reflect.annotation.AnnotationType Class.annotationType                      null
//	     92     4                java.lang.ClassValue.ClassValueMap Class.classValueMap                       null
//	Instance size: 96 bytes
//	Space losses: 32 bytes internal + 0 bytes external = 32 bytes total


//org.balthie.demo.jvm.classloader.lifecircle.SomeClass object internals:
//	 OFFSET  SIZE   TYPE DESCRIPTION                               VALUE
//	      0     4        (object header)                           01 00 00 00 (00000001 00000000 00000000 00000000) (1)
//	      4     4        (object header)                           00 00 00 00 (00000000 00000000 00000000 00000000) (0)
//	      8     4        (object header)                           40 01 00 20 (01000000 00000001 00000000 00100000) (536871232)    SomeClass.class 对象
//	     12     4        (alignment/padding gap)                  
//	     16     8   long SomeClass.appleCount                      10
//	Instance size: 24 bytes
//	Space losses: 4 bytes internal + 0 bytes external = 4 bytes total

//jdk.internal.loader.ClassLoaders$AppClassLoader object internals:
//	 OFFSET  SIZE                                     TYPE DESCRIPTION                               VALUE
//	      0     4                                          (object header)                           01 06 db eb (00000001 00000110 11011011 11101011) (-337967615)
//	      4     4                                          (object header)                           0b 00 00 00 (00001011 00000000 00000000 00000000) (11)
//	      8     4                                          (object header)                           99 a2 00 20 (10011001 10100010 00000000 00100000) (536912537)
//	     12    68                                          (alignment/padding gap)                  
//	     80     4                            java.util.Map SecureClassLoader.pdcache                 (object)
//	     84     4   jdk.internal.loader.BuiltinClassLoader BuiltinClassLoader.parent                 (object)
//	     88     4         jdk.internal.loader.URLClassPath BuiltinClassLoader.ucp                    (object)
//	     92     4                            java.util.Map BuiltinClassLoader.nameToModule           (object)
//	     96     4                            java.util.Map BuiltinClassLoader.moduleToReader         (object)
//	    100     4              java.lang.ref.SoftReference BuiltinClassLoader.resourceCache          (object)
//	Instance size: 104 bytes
//	Space losses: 68 bytes internal + 0 bytes external = 68 bytes total
